package com.artron.mediaartron.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.IntDef;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.WindowManager;

import com.artron.baselib.base.BaseFragment;
import com.artron.baselib.utils.UIUtils;
import com.artron.mediaartron.R;
import com.artron.mediaartron.ui.fragment.StartOneFragment;
import com.artron.mediaartron.ui.fragment.StartTwoFragment;
import com.umeng.analytics.MobclickAgent;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;


/**
 * Class description here
 *
 * @author doing
 * @version 1.0.0
 * @since 2017-12-06.
 */

public class StartActivity extends AppBaseActivity {

    public static final String TYPE = "Type";

    public static final int START_ONE = 6000;
    public static final int START_TWO = 6001;

    @IntDef({START_ONE, START_TWO})
    @Retention(RetentionPolicy.SOURCE)
    @interface StartType {}

    public static void start(Context context,@StartType int type) {
        Intent starter = new Intent(context, StartActivity.class);
        starter.putExtra(TYPE, type);
        context.startActivity(starter);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_general;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        //这一行是放在程序入口处的
        MobclickAgent.startWithConfigure(new MobclickAgent.UMAnalyticsConfig(this, "59f6f5398f4a9d01ef0000f1",
                "UMeng_All"));

        setToolbarShow(false);

        BaseFragment fragment = null;
        @StartType int type = getIntent().getIntExtra(TYPE, START_ONE);
        switch (type) {
            case START_ONE:
                fragment = StartOneFragment.newInstance();
                break;
            case START_TWO:
                fragment = StartTwoFragment.newInstance();
                break;
        }
        if (fragment == null) {
            return;
        }
        List<Fragment> fragments = getSupportFragmentManager().getFragments();
        if (fragments == null || fragments.size() == 0) {
            addFragment(R.id.General_content, fragment, false);
        } else {
            replaceFragment(R.id.General_content, fragment, false);
        }

    }

    public void setToolbarShow(boolean visible) {
        int visibleInt = visible ? View.VISIBLE : View.GONE;

        mToolbar.setVisibility(visibleInt);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            int color = visible ? R.color.white : R.color.transparent;
            getWindow().setStatusBarColor(UIUtils.getColor(color));
        }

        if (visible) {
            final WindowManager.LayoutParams attrs = getWindow().getAttributes();
            attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
            getWindow().setAttributes(attrs);
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        } else {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
    }

}
